import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

@Schema()
export class Preset extends Document {
  @Prop({ required: true })
  name: string;

  @Prop({ required: true })
  category: string;

  @Prop()
  description: string;

  @Prop()
  preview_image?: string;

  @Prop({ required: true })
  template_type: string;

  @Prop({ type: Object, required: true })
  params: Record<string, any>;

  @Prop({ type: [String], default: [] })
  tags: string[];

  @Prop({ required: true })
  created_at: Date;

  @Prop({ required: true })
  updated_at: Date;
}

export const PresetSchema = SchemaFactory.createForClass(Preset);

// 设置虚拟字段 id
PresetSchema.set('toJSON', {
  virtuals: true,
  versionKey: false,
  transform: function (doc, ret) {
    ret.id = ret._id;
    delete ret._id;
    return ret;
  }
}); 